package com.leyou.item.web;

import com.leyou.item.service.SpecGroupService;
import com.leyou.item.service.SpecParamService;
import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/spec")
public class SpecController {
    @Autowired
    private SpecGroupService specGroupService;
    @Autowired
    private SpecParamService specParamService;

    //根据商品分类id 查询规格组的参数的集合 /spec/groups/of/category


    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>>querySpecGroupCategoryId(@RequestParam("id") Long cid){

        return ResponseEntity.ok(this.specGroupService.querySpecGroupCategoryId(cid));
    }
    //根据商品分组id查询规格参数集合

    /**
     * 根据条件查询规格参数集合
     * @param
     * @param gid
     * @param cid
     * @param searching
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>>querySpecParams(
            @RequestParam(value = "groupId", required = false) Long gid,
            @RequestParam(value = "categoryId", required = false) Long cid,
         @RequestParam(value = "searching", required = false) Boolean searching){

        return ResponseEntity.ok( this.specParamService.queryParams(gid,cid,searching));

    }

    @GetMapping("/list")
    public ResponseEntity<List<SpecGroupDTO>> querySpecList(@RequestParam("id") Long cid) {
     return ResponseEntity.ok(this.specGroupService.querySpecList(cid));
    }
}
